import java.math.*

class Comic {
	//	Persistence Attributes
	String 	name
	String 	description
	String 	nameFile
	
	boolean rateable   	= true
	boolean commentable = true
	boolean disabled 	= false
	
	Date 	dateCreated
	Date 	lastUpdated

	
	//	Not Persistence Attributes
	static transients = ['rate']	
	

	
	//	DB Relations
 	static 	belongsTo = [createdBy:	User]
 	
	static 	hasMany = 	[page:		Page,
	                 	 ratings:	Rate,
	                 	 tags:		Tag]

	//	DB Constraits
	static constraints = {
		name(blank:false, unique:true, maxSize:50)
		description(nullable:true, maxSize:1000)
	}

	
	//	Default order to sort
	//static mapping = { sort "name" }

	
	
	//	Other Methods
	String getRate() {
		//	Calculem la mitja de les puntuacions rebudes fins ara
		Float p = 0
		if(ratings){
			ratings.each(){ p += it.rate }
			p = p / ratings.size()
		}
		return p
	}
	
	
	/*String getAbsoluteImagePath() {
		return grailsApplication.config.comics.uploadAbsoluteComicPath + path
	}
	
	String getAbsoluteImagePath(file) {
		return grailsApplication.config.comics.uploadAbsoluteComicPath + file + "/"
	}*/
}